/**
 * Created by 55456 on 2016/4/8.
 */
var sequelizex = require('../lib/sequelizex');
var shortTypes = sequelizex.DataTypes;
module.exports = (sequelize,DataTypes) => {
    return sequelize.define("Story",{
        id : shortTypes.uuidWithPrimary(),

        title : shortTypes.String(),

        flags : shortTypes.String(null,true),

        content : shortTypes.Text(),

        location : shortTypes.String(),

        publicEnable : shortTypes.Int(1),

        updatedAt : {
            type : DataTypes.STRING
        },

        createdAt : {
            type : DataTypes.STRING
        }
    },{
        timestamps:false,
        classMethods:{
            
        },
        hooks:{
           beforeCreate:function(story){
                story.createdAt = Math.round(new Date().getTime()/1000);
               story.updatedAt = Math.round(new Date().getTime()/1000);
           },
           beforeUpdate:function(story){
               story.updatedAt = Math.round(new Date().getTime()/1000);
           }
        },
        associate : function (models) {
            models.Story.belongsToMany(models.User,{through : "UserStory"});
            models.Story.belongsTo(models.User,{as:"MyAuthor",foreignKey:"AuthorID"});
            models.Story.hasMany(models.Comment);
        }
    });
};